# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: neo

import sys

from absl import app, flags

from coin.base.mail_util import (send_mail, send_mail_with_attachments)


def main(argv):
  FLAGS = flags.FLAGS

  assert FLAGS.mailfrom is not None
  assert FLAGS.mailto is not None

  name = FLAGS.name or FLAGS.mailfrom
  subject = FLAGS.subject or ''
  content = sys.stdin.read()

  if FLAGS.attach:
    send_mail_with_attachments(name,
                               FLAGS.mailfrom,
                               FLAGS.mailto,
                               subject,
                               content,
                               FLAGS.attach,
                               font_size=FLAGS.font_size)
  else:
    send_mail(name, FLAGS.mailfrom, FLAGS.mailto, subject, content, font_size=FLAGS.font_size)


if __name__ == '__main__':
  flags.DEFINE_string('name', None, 'Sender name')
  flags.DEFINE_string('mailfrom', 'no-reply@joomo.io', 'From address')
  flags.DEFINE_string('mailto', None, 'To address')
  flags.DEFINE_string('subject', '', 'Subject')
  flags.DEFINE_float('font_size', None, 'Font size in em')
  flags.DEFINE_list('attach', None, 'Attachment. Use comman to attach multiple files.')
  app.run(main)
